import { editUser } from "@/api/modules/user";
import { PublicStore } from "@/stores/modules/public";
import { showTips } from "@/utils/util";
export const changeUserInfo = async (fieldKey: string, value: any) => {
	const publicStore = PublicStore();
	let param: any = { id: publicStore.userInfo.userId };
	param[fieldKey] = value;
	let { code, message } = await editUser(param);
	let ok = showTips(code, "操作", message);
	if (ok) {
		publicStore.userInfo[fieldKey] = value;
	}
	return ok;
};
export const changeUserData = async (userInfo: any, storeKeys: string[]) => {
	const publicStore = PublicStore();
	userInfo.id = publicStore.userInfo.userId;
	let { code, message } = await editUser(userInfo);
	let ok = showTips(code, "操作", message);
	if (ok) {
		storeKeys.forEach(key => {
			publicStore.userInfo[key] = userInfo[key];
		});
	}
	return ok;
};
